<template>
    <!-- 早班会情况统计 -->
    <base-breadcrumb>
        <searchData :searchData="searchOptions" @search="handleSearch" />
        <div class="page-body">
            <a-card :bordered="false">
                <!-- <title-name title="早班会情况统计" /> -->
                <div class="table-operateors mb20">
                    <div class="pub-table-select-count" style="margin: 10px 0">
                        <a-icon type="info-circle" theme="twoTone" />
                        <span>
                            班组数为:
                            <a>{{ totalCount.teamNum || 0 }}</a
                            >，
                        </span>
                        <span>
                            今日已填报早班会:
                            <a>{{ totalCount.hasWriteToday || 0 }}</a
                            >，
                        </span>
                        <span>
                            还未提交:
                            <a>{{ totalCount.hasNoWriteToday || 0 }}</a>
                        </span>
                    </div>
                </div>
                <list-table
                    ref="table"
                    size="default"
                    rowKey="id"
                    :columns="columns"
                    :request="loadData"
                    :alert="true"
                    show-size-changer
                    show-quick-jumper
                    :showPagination="true"
                >
                    <!-- <template slot="status" slot-scope="text, record">
            <StatusDisplay
              :status-code="record.status"
              :status-map="{        DRAFT: {
          label: '未提交',
          color: 'red'
        },
        SUBMITTED: {
          label: '已提交',
          color: 'green'
        }}"
            />
          </template> -->
                    <span slot="status" slot-scope="text, record">
                        <list-status :status="record.status" conversion="en" :text="text"></list-status>
                    </span>
                </list-table>
            </a-card>
        </div>
    </base-breadcrumb>
</template>

<script>
import StatusDisplay from '@/components/StatusDisplay'
import { getRecordStatistics, getMorningShiftCount } from '@/api/safetySupervision/morningMeeting.js'
import { STable } from '@/components'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'

const searchOptions = [
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },
]

const columns = [
    {
        title: '班组',
        dataIndex: 'teamName',
    },
    {
        title: '班组长',
        dataIndex: 'creatorName',
    },
    {
        title: '分包公司',
        dataIndex: 'subcontractComName',
    },
    {
        title: '所属分公司',
        dataIndex: 'branchComName',
    },
    {
        title: '所属项目',
        dataIndex: 'projectName',
    },
    {
        title: '最后提交时间',
        dataIndex: 'modifiedTime',
    },
    {
        title: '今日提交情况',
        dataIndex: 'status',
        scopedSlots: { customRender: 'status' },
    },
]

export default {
    name:'a'+Date.now(),    components: {
        STable,
        StatusDisplay,
    },
    data() {
        return {
            statisticsInfo: {
                teamNum: 0, // 班组数
                morningShiftNum: 0, // 早班数
                unCommit: 0, // 未提交数
            },
            totalCount: {
              teamNum: 0, // 班组数
              hasWriteToday: 0, // 早班数
              hasNoWriteToday: 0, // 未提交数
            },
            searchOptions: searchOptions,
            columns: columns,
            queryParam: {},
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                this.getMorningShiftCount(requestParameters)
                const [err, res] = await getRecordStatistics(requestParameters)
                 return {
                   code: 200,
                   ...res.data,
                   data: res.data,
                   totalSize:res.totalSize,
                   totalPage:res.totalPage,
                   currentPage:res.currentPage
                 }
            },
        }
    },
    methods: {
        handleSearch(val = {}) {
            this.queryParam = val
            this.$refs.table.refresh(true)
        },
        async getMorningShiftCount(params) {
          const [err, res] = await getMorningShiftCount(params)
          if (!err) {
            // this.statisticsInfo = res.data
            this.totalCount = res.data
          }
        },
        // 获取统计信息
        async getRecordStatistics(params) {
            const [err, res] = await getRecordStatistics(params)
            console.log(res)
            if (!err) {
                this.statisticsInfo = res.data
                console.log(this.statisticsInfo)
            }
        },
    },
}
</script>

<style lang="less" scoped>
.page-header {
    .header-row {
        display: flex;
        .flex-content {
            flex: auto;
        }
        .divider {
            margin: 0 12px;
        }
        .expand-btn {
            margin-left: 8px;
            font-size: 14px;
        }
    }
}
.page-body {
    .table-operateors {
        .ant-btn + .ant-btn {
            margin-left: 12px;
        }
    }
}
</style>